﻿// Decompiled with JetBrains decompiler
// Type: Netick.NetworkStringHelper
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

using System;
using System.Runtime.CompilerServices;
using System.Text;

#nullable disable
namespace Netick;

internal static class NetworkStringHelper
{
  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  internal static unsafe void SetString(string source, char* ptrChar, int size)
  {
    int index1 = Math.Min(size, source.Length + 1);
    for (int index2 = 0; index2 < index1; ++index2)
      ptrChar[index2] = source[index2];
    ptrChar[index1] = char.MinValue;
  }

  public static unsafe void LoadPtrStringIntoStringBuilder(
    StringBuilder builder,
    char* ptr,
    int charCount)
  {
    builder.Clear();
    for (int index = 0; index < charCount && ptr[index] != char.MinValue; ++index)
      builder.Append(ptr[index]);
  }

  [MethodImpl(MethodImplOptions.AggressiveInlining)]
  internal static unsafe string GetString(char* ptrChar, int size)
  {
    StringBuilder stringBuilder = new StringBuilder(size);
    for (int index = 0; index < size && ptrChar[index] != char.MinValue; ++index)
      stringBuilder.Append(ptrChar[index]);
    return stringBuilder.ToString();
  }
}
